package com.his.struts.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.his.struts.form.UserForm;
/**
 * 用户过滤器
 * @author xaioweiliang
 *
 */
public class UserFilter implements Filter {

	Logger log = Logger.getLogger(UserFilter.class);
	public void destroy() {
		//log.info("用户--过滤器已关闭");
	}

	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;
		HttpServletResponse response = (HttpServletResponse)res;
		UserForm user = (UserForm)request.getSession().getAttribute("userinfo");
		if(user != null){
			chain.doFilter(request, response);
		} else {
			response.sendRedirect("/his/front/userLogin.jsp");
		}
	}

	public void init(FilterConfig arg0) throws ServletException {
		//log.info("用户--过滤器已启动");
	}

}
